<?php

require_once(SY_DIR . '/helpers/HTMLElement.php');

class MenuItemHelper extends Helper
{

  const ICON = 'icon';

  const LABEL = 'label';

  const BOTH = 'both';

  public static $mode = 'both';

  public function show($item, $mode = null)
  {
    if (empty($mode)) {
      $mode = self::$mode;
    }

    $output = '';

    if ($item instanceof MenuItem) {
      $route = is_array($item->url) ? sy_get_param($item->url, 0) : $item->url;
      $params = is_array($item->url) ? sy_get_param($item->url, 1) : null;
      $label = is_array($item->label) ? sy_get_param($item->label, 0) : $item->label;
      $icon = is_array($item->label) ? sy_get_param($item->label, 1) : null;
    }
    else {
      $route = sy_get_param($item, 'route');
      $params = sy_get_param($item, 'params');
      $label = sy_get_param($item, 'label');
      $icon = sy_get_param($item, 'icon');
    }

    if (! empty($icon)) {
      $output .= e('span', array('class' => 'icon ' . 'icon-' . $icon));
    }
    else {
      $output .= e('span', array('class' => 'icon ' . 'icon-none'));
    }

    $output .= e('span', array('class' => 'label'))->append($label);

    if (! empty($route)) {
      $linkParams = (array) sy_get_param($params, 'linkParams');
      $linkParams['href'] = s::response()->makeUrl($route, $params);
      $linkParams['title'] = $label;
      $linkParams['alt'] = $label;
      $linkParams['class'] = 'menu-label';

      $output = e('a', $linkParams)->append($output);
    }
    else {
      $output = e('span', array('class' => 'menu-label'))->append($output);
    }

    return $output;
  }

}

?>